﻿/*
* 
*
* 功 能： N/A
* 类 名： BDZDJY
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2013/7/17 23:06:29   N/A    初版
*
*/
using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;

using DQYT.HTDZ.IDAL;
using Maticsoft.DBUtility;
using DQYT.HTDZ.Model;

namespace DQYT.HTDZ.OracleDAL
{
	/// <summary>
	/// 数据访问类:BDZDJY
	/// </summary>
	public partial class BDZDJYDAL:IBDZDJY
	{
		public BDZDJYDAL()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(decimal ID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from BDZDJY");
			strSql.Append(" where ID=:ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,22)			};
			parameters[0].Value = ID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(BDZDJYModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into BDZDJY(");
			strSql.Append("ID,WELLID,PULLID,ZDSJ,ZJGL,WGBC,CYJYXFX,PHTZ,PZTZ,FGQK,GYQK,CCTZ,CCITZ,PJDDJXN,PJCYJXN,PJJNGXN,PJSBGLSP)");
			strSql.Append(" values (");
            strSql.Append("HTDZ_ID.nextval,:WELLID,:PULLID,:ZDSJ,:ZJGL,:WGBC,:CYJYXFX,:PHTZ,:PZTZ,:FGQK,:GYQK,:CCTZ,:CCITZ,:PJDDJXN,:PJCYJXN,:PJJNGXN,:PJSBGLSP)");
			OracleParameter[] parameters = {
					new OracleParameter(":WELLID", OracleType.VarChar,30),
					new OracleParameter(":PULLID", OracleType.Number,18),
					new OracleParameter(":ZDSJ", OracleType.DateTime),
					new OracleParameter(":ZJGL", OracleType.VarChar,300),
					new OracleParameter(":WGBC", OracleType.VarChar,300),
					new OracleParameter(":CYJYXFX", OracleType.VarChar,300),
					new OracleParameter(":PHTZ", OracleType.VarChar,300),
					new OracleParameter(":PZTZ", OracleType.VarChar,300),
					new OracleParameter(":FGQK", OracleType.VarChar,300),
					new OracleParameter(":GYQK", OracleType.VarChar,300),
					new OracleParameter(":CCTZ", OracleType.VarChar,300),
					new OracleParameter(":CCITZ", OracleType.VarChar,300),
					new OracleParameter(":PJDDJXN", OracleType.VarChar,300),
					new OracleParameter(":PJCYJXN", OracleType.VarChar,300),
					new OracleParameter(":PJJNGXN", OracleType.VarChar,300),
					new OracleParameter(":PJSBGLSP", OracleType.VarChar,300)};
			parameters[0].Value = model.ID;
			parameters[1].Value = model.WELLID;
			parameters[2].Value = model.PULLID;
			parameters[3].Value = model.ZDSJ;
			parameters[4].Value = model.ZJGL;
			parameters[5].Value = model.WGBC;
			parameters[6].Value = model.CYJYXFX;
			parameters[7].Value = model.PHTZ;
			parameters[8].Value = model.PZTZ;
			parameters[9].Value = model.FGQK;
			parameters[10].Value = model.GYQK;
			parameters[11].Value = model.CCTZ;
			parameters[12].Value = model.CCITZ;
			parameters[13].Value = model.PJDDJXN;
			parameters[14].Value = model.PJCYJXN;
			parameters[15].Value = model.PJJNGXN;
			parameters[16].Value = model.PJSBGLSP;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
        public bool Update(BDZDJYModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update BDZDJY set ");
			strSql.Append("WELLID=:WELLID,");
			strSql.Append("PULLID=:PULLID,");
			strSql.Append("ZDSJ=:ZDSJ,");
			strSql.Append("ZJGL=:ZJGL,");
			strSql.Append("WGBC=:WGBC,");
			strSql.Append("CYJYXFX=:CYJYXFX,");
			strSql.Append("PHTZ=:PHTZ,");
			strSql.Append("PZTZ=:PZTZ,");
			strSql.Append("FGQK=:FGQK,");
			strSql.Append("GYQK=:GYQK,");
			strSql.Append("CCTZ=:CCTZ,");
			strSql.Append("CCITZ=:CCITZ,");
			strSql.Append("PJDDJXN=:PJDDJXN,");
			strSql.Append("PJCYJXN=:PJCYJXN,");
			strSql.Append("PJJNGXN=:PJJNGXN,");
			strSql.Append("PJSBGLSP=:PJSBGLSP");
			strSql.Append(" where ID=:ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":WELLID", OracleType.VarChar,30),
					new OracleParameter(":PULLID", OracleType.Number,18),
					new OracleParameter(":ZDSJ", OracleType.DateTime),
					new OracleParameter(":ZJGL", OracleType.VarChar,300),
					new OracleParameter(":WGBC", OracleType.VarChar,300),
					new OracleParameter(":CYJYXFX", OracleType.VarChar,300),
					new OracleParameter(":PHTZ", OracleType.VarChar,300),
					new OracleParameter(":PZTZ", OracleType.VarChar,300),
					new OracleParameter(":FGQK", OracleType.VarChar,300),
					new OracleParameter(":GYQK", OracleType.VarChar,300),
					new OracleParameter(":CCTZ", OracleType.VarChar,300),
					new OracleParameter(":CCITZ", OracleType.VarChar,300),
					new OracleParameter(":PJDDJXN", OracleType.VarChar,300),
					new OracleParameter(":PJCYJXN", OracleType.VarChar,300),
					new OracleParameter(":PJJNGXN", OracleType.VarChar,300),
					new OracleParameter(":PJSBGLSP", OracleType.VarChar,300),
					new OracleParameter(":ID", OracleType.Number,18)};
			parameters[0].Value = model.WELLID;
			parameters[1].Value = model.PULLID;
			parameters[2].Value = model.ZDSJ;
			parameters[3].Value = model.ZJGL;
			parameters[4].Value = model.WGBC;
			parameters[5].Value = model.CYJYXFX;
			parameters[6].Value = model.PHTZ;
			parameters[7].Value = model.PZTZ;
			parameters[8].Value = model.FGQK;
			parameters[9].Value = model.GYQK;
			parameters[10].Value = model.CCTZ;
			parameters[11].Value = model.CCITZ;
			parameters[12].Value = model.PJDDJXN;
			parameters[13].Value = model.PJCYJXN;
			parameters[14].Value = model.PJJNGXN;
			parameters[15].Value = model.PJSBGLSP;
			parameters[16].Value = model.ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(decimal ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BDZDJY ");
			strSql.Append(" where ID=:ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,22)			};
			parameters[0].Value = ID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string IDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BDZDJY ");
			strSql.Append(" where ID in ("+IDlist + ")  ");
			int rows=DbHelperOra.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
        public BDZDJYModel GetModel(decimal ID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,WELLID,PULLID,ZDSJ,ZJGL,WGBC,CYJYXFX,PHTZ,PZTZ,FGQK,GYQK,CCTZ,CCITZ,PJDDJXN,PJCYJXN,PJJNGXN,PJSBGLSP from BDZDJY ");
			strSql.Append(" where ID=:ID ");
			OracleParameter[] parameters = {
					new OracleParameter(":ID", OracleType.Number,22)			};
			parameters[0].Value = ID;

            BDZDJYModel model = new BDZDJYModel();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
        public BDZDJYModel DataRowToModel(DataRow row)
		{
            BDZDJYModel model = new BDZDJYModel();
			if (row != null)
			{
				if(row["ID"]!=null && row["ID"].ToString()!="")
				{
					model.ID=decimal.Parse(row["ID"].ToString());
				}
				if(row["WELLID"]!=null)
				{
					model.WELLID=row["WELLID"].ToString();
				}
				if(row["PULLID"]!=null && row["PULLID"].ToString()!="")
				{
					model.PULLID=decimal.Parse(row["PULLID"].ToString());
				}
				if(row["ZDSJ"]!=null && row["ZDSJ"].ToString()!="")
				{
					model.ZDSJ=DateTime.Parse(row["ZDSJ"].ToString());
				}
				if(row["ZJGL"]!=null)
				{
					model.ZJGL=row["ZJGL"].ToString();
				}
				if(row["WGBC"]!=null)
				{
					model.WGBC=row["WGBC"].ToString();
				}
				if(row["CYJYXFX"]!=null)
				{
					model.CYJYXFX=row["CYJYXFX"].ToString();
				}
				if(row["PHTZ"]!=null)
				{
					model.PHTZ=row["PHTZ"].ToString();
				}
				if(row["PZTZ"]!=null)
				{
					model.PZTZ=row["PZTZ"].ToString();
				}
				if(row["FGQK"]!=null)
				{
					model.FGQK=row["FGQK"].ToString();
				}
				if(row["GYQK"]!=null)
				{
					model.GYQK=row["GYQK"].ToString();
				}
				if(row["CCTZ"]!=null)
				{
					model.CCTZ=row["CCTZ"].ToString();
				}
				if(row["CCITZ"]!=null)
				{
					model.CCITZ=row["CCITZ"].ToString();
				}
				if(row["PJDDJXN"]!=null)
				{
					model.PJDDJXN=row["PJDDJXN"].ToString();
				}
				if(row["PJCYJXN"]!=null)
				{
					model.PJCYJXN=row["PJCYJXN"].ToString();
				}
				if(row["PJJNGXN"]!=null)
				{
					model.PJJNGXN=row["PJJNGXN"].ToString();
				}
				if(row["PJSBGLSP"]!=null)
				{
					model.PJSBGLSP=row["PJSBGLSP"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ID,WELLID,PULLID,ZDSJ,ZJGL,WGBC,CYJYXFX,PHTZ,PZTZ,FGQK,GYQK,CCTZ,CCITZ,PJDDJXN,PJCYJXN,PJJNGXN,PJSBGLSP ");
			strSql.Append(" FROM BDZDJY ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM BDZDJY ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.ID desc");
			}
			strSql.Append(")AS Row, T.*  from BDZDJY T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "BDZDJY";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

